Skip to content

Add cwd to AgentConfig.mcpServers[] for stdio working directory#1042

Open
JustinElst wants to merge 1 commit intokelos-dev:mainfrom
JustinElst:feat/agentconfig-mcp-cwd
Open

Add cwd to AgentConfig.mcpServers[] for stdio working directory#1042
JustinElst wants to merge 1 commit intokelos-dev:mainfrom
JustinElst:feat/agentconfig-mcp-cwd

Conversation

@JustinElst
Copy link
Copy Markdown

@JustinElst JustinElst commented Apr 28, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds an optional cwd field to AgentConfig.mcpServers[] so callers can pin the working directory of stdio MCP servers.

Stdio MCP servers run with whatever CWD the agent process happens to be in. That's fine for most servers, but breaks servers that must execute from a specific project root. Laravel Boost is the canonical example: php artisan boost:mcp only works when CWD is the Laravel project root. Without cwd, callers have to patch the repo's .mcp.json at runtime to inject a cd /workspace/repo && exec wrapper, which is a file-write side effect inside the workspace that's easy to get wrong.

The field is plumbed through buildMCPServersJSON into the .mcp.json-shaped JSON exposed via KELOS_MCP_SERVERS. The claude-code, cursor, and gemini entrypoints pick it up transparently because they merge the inner mcpServers map into the agent's user-scoped config via Object.assign. The codex entrypoint converts the JSON to TOML field-by-field, so this PR also adds cwd to its TOML emission alongside the other stdio fields.

cwd is omitted from the rendered JSON when WorkingDir is unset, so existing configs are unaffected.

Which issue(s) this PR is related to:

N/A

Special notes for your reviewer:

  • The field is documented as stdio-only. For http/sse servers the field is still serialized if set, but the agent transports for those types ignore it.
  • claude-code already honors cwd on stdio MCP entries per its MCP schema, so no claude-side change is needed.
  • Two new unit tests cover the field passing through to the rendered JSON and being omitted when unset.

Does this PR introduce a user-facing change?

Add `cwd` to `AgentConfig.mcpServers[]` to set the working directory of a stdio MCP server. Useful for servers that must run from a specific project root, e.g. `php artisan boost:mcp` from a Laravel project root.

Stdio MCP servers run with whatever current working directory the
agent process happens to be in. That is fine for most servers, but
breaks servers that must execute from a specific project root.
Laravel Boost is the canonical example: "php artisan boost:mcp"
only works when CWD is the Laravel project root, so callers
currently have to patch the project-scope ".mcp.json" at runtime
to inject a "cd /workspace/repo && exec" wrapper.

This adds an optional WorkingDir field (YAML key "cwd") to
MCPServerSpec. The field is plumbed through buildMCPServersJSON
into the .mcp.json-shaped JSON exposed via KELOS_MCP_SERVERS, so
the claude-code, cursor, and gemini entrypoints pick it up
transparently (they merge the inner mcpServers map into the
agent's user-scoped config). The codex entrypoint, which converts
the JSON into TOML field-by-field, is updated to emit cwd alongside
the other stdio fields.

cwd is omitted from the rendered JSON when WorkingDir is unset, so
existing configs are unaffected. The field is documented as stdio-
only; for http/sse servers the agent transports ignore it.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature needs-actor needs-priority needs-triage release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant